import com.google.appengine.api.datastore.KeyFactory

if (params["id"]) {
	
 def id = Long.parseLong(params["id"])
 println "id=$id"

 try {
   def key = KeyFactory.createKey("foto", id)
   def imagen = datastore.get(key)
   
   println "foto = $imagen.nombre"
   
   if (imagen.imagen) {
	   byte[] bytes = imagen.imagen.getBytes()
	   println "hay datos... ${bytes.length}"
   } else {
	   println "no hay datos"
   }

   request.setAttribute "imagen", imagen

   forward "ver.gtpl"

   } catch (Throwable t) {
    //forward to some error page...
   }
} else {
 forward "index.gtpl"
}



def muestraImagen(def imagen) {
	String contentType = "application/octet-stream"
	
	int contentLength = imagen.length

    response.reset()

    if (imagen != null) {
        response.setContentType(contentType)
        response.setContentLength(contentLength)
        output = new BufferedOutputStream(response.getOutputStream())

        output.write(imagen)
    }
	
	
}